package com.iemes.controller.purchase;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.BrandFormMap;
import com.iemes.entity.BrandModelFormMap;
import com.iemes.entity.DepartmentForMap;
import com.iemes.entity.GoodsreturnFormMap;
import com.iemes.entity.PurchaseFromMap;
import com.iemes.entity.QualityFromMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.SuppfilleMapper;
import com.iemes.mapper.material.GoodsReturnMapper;
import com.iemes.mapper.material.PurchaseMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;


@RequestMapping("/goodret/")
@Controller
public class GoodsRreController extends BaseController {

	@Inject
	private GoodsReturnMapper goodsMapper;
	@Inject
	private SuppfilleMapper suppMapper;
	@Inject
	private PurchaseMapper purMapper;
	
	@RequestMapping("examineGood")
	public String examinepru(Model model){
		List<PurchaseFromMap> purFormMaps=purMapper.findByWhere(new PurchaseFromMap());
		model.addAttribute("pur", purFormMaps);
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/material_pur/goods_ret/goods_ret_list";
	}
	
	@ResponseBody
	@RequestMapping("goodret_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		GoodsreturnFormMap goodretFromMap = getFormMap(GoodsreturnFormMap.class);
		List<Map<String, Object>> goodretMaps=goodsMapper.getAllName(goodretFromMap);
		LuogicPaging(pageNow, pageSize, goodretMaps);
		pageView.setRecords(goodretMaps);
		return pageView;
	}
	@ResponseBody
	@RequestMapping("goodret_delEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module="物料管理",methods="采购订单-删除采购清单")//凡需要处理业务逻辑的.都需要记录操作日志
	public String deleteEntity() throws Exception {
		GoodsreturnFormMap goodFormMap=getFormMap(GoodsreturnFormMap.class);
		PurchaseFromMap purFormMap=getFormMap(PurchaseFromMap.class);
		String[] ids = getParaValues("ids");
		String arr=ids[0];
		String[] str=arr.split(",");
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date();
		for(int i=0;i<str.length;i++){
			goodFormMap.put("date", sdf.format(date));
			goodFormMap.set("operation", 2);
			purFormMap.set("applyId", 3);
			purFormMap.set("whetherpass", 1);
			goodFormMap.put("id", str[i]);
			suppMapper.editEntity(goodFormMap);
		}
		return "success";
	}
	
}
